package com.ccom.test.controller;

import com.ccom.core.common.constant.ServiceNameConstants;
import com.ccom.core.common.model.Result;
import com.ccom.test.service.TransactionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description:
 * @Author: zjj
 * @Date: 2021/12/22
 */
@Slf4j
@Api(tags = "事务传播机制测试")
@RestController
@RequestMapping(ServiceNameConstants.TEST_SERVICE_URL_PREFIX + "/transaction")
public class TransactionController {
    @Autowired
    private TransactionService transactionService;

    @GetMapping("/addWithTransactional")
    @ApiOperation(value = "测试事务-带事务")
    private Result addWithTransactional(@RequestParam("userId") Long userId){
        transactionService.addArticle(userId);
        return Result.success();
    }

    @GetMapping("/addWithNoTransactional")
    @ApiOperation(value = "测试事务-不带事务")
    private Result addWithNoTransactional(@RequestParam("userId") Long userId){
        transactionService.addArticle1(userId);
        return Result.success();
    }
}
